﻿namespace GSC.WebControls
{
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    /// <summary>
    /// 后台控件基类。
    /// </summary>
    /// <remarks>后台控件基类。</remarks>
    public abstract class UserControlBase : System.Web.UI.UserControl, IUpdateCulture, IManageMaster, IGetLocalResourceObject
    {
        #region IGetLocalResourceObject
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        object IGetLocalResourceObject.GetLocalResourceObject(string key)
        {
            return this.GetLocalResourceObject(key);
        }
        #endregion
        #region IManageMaster
        /// <summary>
        /// 获取框架控件。
        /// </summary>
        /// <remarks>获取框架控件。</remarks>
        protected BackgroundControl BackgroundControl;
        /// <summary>
        /// 
        /// </summary>
        BackgroundControl IManageMaster.BackgroundControl
        {
            get
            {
                return BackgroundControl;
            }
            set
            {
                BackgroundControl = value;
            }
        }
        #endregion
        #region IUpdateCulture
        /// <summary>
        /// 更新区域信息。
        /// </summary>
        /// <remarks>更新区域信息。</remarks>
        protected abstract void OnUpdateCulture();
        /// <summary>
        /// 更新区域接口。
        /// </summary>
        void IUpdateCulture.UpdateCulture()
        {
            this.OnUpdateCulture();
            //更新浏览器标题。
            this.OnUpdateTitle();
        }
        #endregion
        /// <summary>
        /// 
        /// </summary>
        protected virtual void UpdateComplete()
        {
            //
            AsyncListLoadingWaitControl.UpdateComplete();
        }
        /// <summary>
        /// 更新浏览器标题。
        /// </summary>
        /// <remarks>更新浏览器标题。</remarks>
        protected abstract void OnUpdateTitle();
        /// <summary>
        /// 加载控件完成。
        /// </summary>
        /// <remarks>加载控件完成。</remarks>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            //重写基类。
            base.OnLoad(e);
            //更新浏览器标题。
            this.OnUpdateTitle();
        }
        /// <summary>
        /// 语言接口。
        /// </summary>
        protected ILanguage ILanguage;
        /// <summary>
        /// 数据接口。
        /// </summary>
        protected IData IData;
        /// <summary>
        /// 异步接在等待控件。
        /// </summary>
        protected AsyncListLoadingWaitControl AsyncListLoadingWaitControl;
        /// <summary>
        /// Ajax管理控件。
        /// </summary>
        protected ScriptManager ScriptManager;
        /// <summary>
        /// 初始化控件。
        /// </summary>
        /// <remarks>初始化控件。</remarks>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            //重载基类。
            base.OnInit(e);
            //获取页面数据接口对象。
            this.IData =this.Page as IData;
            //获取页面语言接口对象。
            this.ILanguage = this.Page as ILanguage;
            //创建语言信息。
#if DEBUG
            if (this.ILanguage == null)
            {
               Console.WriteLine("ILanguage 接口对象为空错误！");
            }
            else
            {
                this.ILanguage.CreatedLanguage();
            }
#else
            if (this.ILanguage != null)
            {
                this.ILanguage.CreatedLanguage();
            }
#endif
            //获取Ajax管理控件。
            this.ScriptManager = ScriptManager.GetCurrent(this.Page);
            //获取异步接在等待控件。
            this.AsyncListLoadingWaitControl = AsyncListLoadingWaitControl.GetCurrent(this.Page);
            //
            this.OnUpdateCulture();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="control"></param>
        protected virtual void RegisterControl(Control control)
        {
            this.AsyncListLoadingWaitControl.RegisterControl(control);
        }
    }
}